import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询成品仓成品库存查询
 */
export async function pageMesProductInventorys(params) {
  const res = await request.get('/mes/mesProductInventory/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部成品仓成品库存查询
 */
export async function listMesProductInventorys(params) {
  const res = await request.get('/mes/mesProductInventory/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询成品仓成品库存查询
 */
export async function getMesProductInventory(id) {
  const res = await request.get('/mes/mesProductInventory/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加成品仓成品库存查询
 */
export async function addMesProductInventory(data) {
  const res = await request.post('/mes/mesProductInventory', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改成品仓成品库存查询
 */
export async function updateMesProductInventory(data) {
  const res = await request.put('/mes/mesProductInventory', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除成品仓成品库存查询
 */
export async function removeMesProductInventory(id) {
  const res = await request.delete('/mes/mesProductInventory/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除成品仓成品库存查询
 */
export async function removeMesProductInventorys(ids) {
  const res = await request.delete('/mes/mesProductInventory/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出成品仓成品库存查询
 */
export async function exportMesProductInventorys(params) {
  const res = await request({
    url: '/mes/mesProductInventory/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesProductInventory_${Date.now()}.xlsx`);
}
